package com.qf.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qf.entity.TbGoodDetail;
import com.qf.service.TbGoodDetailService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * (TbGoodDetail)表控制层
 *
 * @author makejava
 * @since 2021-04-06 09:44:32
 */
@RestController
@RequestMapping("tbGoodDetail")
public class TbGoodDetailController {
    /**
     * 服务对象
     */
    @Resource
    private TbGoodDetailService tbGoodDetailService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public TbGoodDetail selectOne(Integer id) {
        return this.tbGoodDetailService.queryById(id);
    }

    @PostMapping("selectCount")
    public int selectCount(@RequestBody String arr) {
        String[] arrs = arr.split(",");
        int[] detailIds = new int[arrs.length - 1];
        for (int i = 0; i < arrs.length - 1; i++) {
            detailIds[i] = Integer.parseInt(arrs[i]);
        }
        int goodId = Integer.parseInt(arrs[arrs.length - 1]);
        return tbGoodDetailService.queryCount(goodId,detailIds);
    }

}